﻿/*
here is the control the index page
 */

//loadTimeout($(".loadingdiv"));
//when cookie is not null go to main directly
var checkCookie = function() {
	if (User != null && User != undefined && User.userName != null && User.password != null) {
		location.href = "Views/main1.html";
	}
};

// control loginbutton
function loginButton() {
	$("#LoginLink").button().click(function(event) {

		// bool if to get the result
		if ($("#LoginEmail").val() == 'manfred.hauswirth@deri.org' && $("#LoginPassword").val() == "aa") {

			User.userName = "manfred hauswirth";
			User.password = $("#LoginPassword").val();
			User.Email = $("#LoginEmail").val();
			UserFactory.save();

			location.href = "Views/main1.html";// the page need to go
			// to
		}
	});
}

function registerButton() {
	$("#registerLink").button().click(function() {
		// now just do easy save here will add function if I got api for login

		User.userName = "userName";
		User.password = $("#registerPassword").val();
		User.Email = $("#registerEmail").val();
		UserFactory.save();

		location.href = "Views/main1.html";// the page need to go
	});
}

// main in
$(function() {
	if (mobilecheck()) {
		location.href = "mobile/index.html";// to mobile
	}

	initialInput();

	checkCookie();
	$("input").val("");// ensure the input is empty

	loginButton();
	registerButton();
});
